<template>
  <div class="main">
    <eagle-input
      class="input_text"
      label="适用范围"
      placeholder="请输入"
      isInputText
      v-model="form.Scope"
      required
    >
    </eagle-input>
    <eagle-input
      class="input_text"
      label="应急小组名称"
      type="textarea"
      rows="1"
      isInputText
      v-model="form.EmergencyTeamName"
      name="emergencyTeamName"
      placeholder="请输入"
      required
    >
    </eagle-input>
    <div class="btn_submit">
      <eagle-button block type="primary" @click="_submit">
        保存
      </eagle-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: this.$route.query.id,
      form: {},
      filter: {
        id: this.$route.query.id,
      },
    };
  },
  created() {
    if (this.id > 0) {
      this.getDetail();
    } else {
      this.initData();
    }
  },
  methods: {
    getDetail() {
      let _this = this;
      _this.$axios
      .get("/PlanEmergencyOrgTeam/GetAddDetail",{params:_this.filter})
      .then((res) => {
        _this.form = res.data;
      });
    },
    initData() {
      let _this = this;
      _this.$axios
      .get("/PlanEmergencyOrgTeam/InitNewEntity",{params:_this.filter})
      .then((res) => {
        _this.form = res.data;
      });
    },
    // 保存
    _submit() {
      if (!this.form.Scope) {
        this.$toast("请输入适用范围");
        return;
      }
      if (!this.form.EmergencyTeamName) {
        this.$toast("请输入应急小组名称");
        return;
      }
      let param = {
        ID: this.id,
        Scope: this.form.Scope,
        EmergencyTeamName: this.form.EmergencyTeamName,
      };
      let _this = this;
      _this.$axios
      .post("/PlanEmergencyOrgTeam/PostData",param)
        .then((res) => {
          _this.$toast("保存成功");
          _this.loading = false;
          setTimeout(() => {
            _this.$router.goRefresh();
          }, 500);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less">
.block {
  width: 120px;
  height: 120px;
  background-color: #fff;
}
</style>
<style lang="less" scoped>
.space-between {
  justify-content: space-between;
}
</style>
